<?php
/**** 4/20/10 Document.php v0.5 by Chris Morrow ****/


class Document {
	public $version = '1.0';
	public $encoding = 'UTF-8';
	public $ns;
	public $nsURI;
	public $publicID;
	public $systemID;
	public $file;
	public $contents;
	protected $root;
	protected $dom;

	public function __construct($source) {
		if(is_file($source) && file_exists($source)) {
			$this->file = $source;
		}
		else {
			$this->contents = $source;
		}
	}

	protected function output() {
		$this->dom->formatOutput = TRUE;
		echo $this->dom->saveXML();
		return true;
	}

	protected function save() {
		$this->dom->formatOutput = TRUE;
		$this->dom->save();
		return true;
	}
	
	protected function generate() {
		$imp = new DOMImplementation();
		$docType = $imp->createDocumentType($this->ns, $this->publicID, $this->systemID);
		$this->dom = $imp->createDocument($this->nsURI, $this->ns, $docType);
		$this->dom->encoding = $this->encoding;
	}
	
	protected function import() {
		$this->dom->loadXML($this->contents);
		return true;
	}
	
	protected function importFile() {
		if(!file_exists($this->file)) {
			return false;
		}
		$this->dom = new DOMDocument();
		$this->dom->preserveWhiteSpace = FALSE;
		$this->dom->load(realpath($this->file));
		return true;
	}
}

?>